<!--
 * @Author: lwy 1245883359@qq.com
 * @Date: 2025-02-20 20:50:09
 * @LastEditors: lwy 1245883359@qq.com
 * @LastEditTime: 2025-02-25 21:40:00
 * @FilePath: \wangyu-new-hetong\src\views\system\zjCount\counter.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="app-page-box">
    <div class="app-page">
      <div class="state">
        <img src="/@/assets/images/count.png" alt="" />
        租金计算器
      </div>
      <div class="content" style="width: 95%; margin: auto">
        <div class="plan-desc">
          <div class="plan-name">{{priceSchemeSelected.templateName||'常规报价'}}</div>
          <div class="plan-info" style="text-align: right">
            <!-- <span>租赁期限：<em>36个月</em></span>
            <span>还款间隔：<em>月</em></span>
            <span>计算方式：<em>利息递减</em></span>
            <span>报价利率：<em>3.99%</em></span> -->
          </div>
        </div>
        <a-form layout="inline" class="query-form" :model="formData" :label-col="labelCol" :wrapper-col="wrapperCol">
          <a-row type="flex">
            <a-col :span="8" v-show="priceSchemeSelected.discountFlag == '1'">
              <a-form-item label="品牌型号：" name="deviceType">
                <a-cascader
                  style="width: 400rem"
                  v-model:value="formData.deviceType"
                  filter
                  :options="deviceOptions"
                  placeholder="请选择"
                  @change="handleBrandDiscountChange"
                />
              </a-form-item>
            </a-col>
            <a-col :span="8">
              <a-form-item label="购置总价：" name="purchaseAmt">
                <a-input-number
                  style="width: 400rem"
                  placeholder="请输入"
                  v-model:value="formData.purchaseAmt"
                  :min="0.0"
                  :precision="2"
                  :step="1"
                  @change="handleMoneyChange(1)"
                  @blur="blurNumber"
                />
              </a-form-item>
            </a-col>
            <a-col :span="8">
              <a-form-item label="首付比例：" name="firstPayRate">
                <a-select v-model:value="formData.firstPayRate" @change="handleMoneyChange(2)" clearable placeholder="请选择" style="width: 400rem">
                  <a-select-option value="0.1">10%</a-select-option>
                  <a-select-option value="0.2">20%</a-select-option>
                  <a-select-option value="0.3">30%</a-select-option>
                  <a-select-option value="0.4">40%</a-select-option>
                  <a-select-option value="0.5">50%</a-select-option>
                  <a-select-option value="0.6">60%</a-select-option>
                  <a-select-option value="0.7">70%</a-select-option>
                  <a-select-option value="0.8">80%</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :span="8">
              <a-form-item label="首付金额：" name="firstPayAmt">
                <a-input-number
                  style="width: 400rem"
                  :min="0.0"
                  :precision="2"
                  :step="1"
                  @blur="blurNumber"
                  v-model:value="formData.firstPayAmt"
                  @change="handleMoneyChange(3)"
                  placeholder="请输入"
                />
              </a-form-item>
            </a-col>

            <a-col :span="8">
              <a-form-item label="融资金额：" name="financeAmt">
                <a-input-number v-model:value="formData.financeAmt" :min="0" :disabled="true" placeholder="请输入" style="width: 400rem" />
              </a-form-item>
            </a-col>

            <a-col :span="8">
              <a-form-item label="计划起租日：" name="startDate">
                <a-date-picker
                  v-model:value="formData.startDate"
                  value-format="YY-MM-DD"
                  :allowClear="false"
                  placeholder="请选择"
                  style="width: 400rem"
                />
              </a-form-item>
            </a-col>

            <a-col :span="8">
              <a-form-item label="租赁期限：" name="limitMonth">
                <a-select v-model:value="formData.limitMonth" @change="handleLeaseTerm" placeholder="请选择" style="width: 400rem">
                  <a-select-option v-for="m in 36" :key="m" :value="m">{{ m + '个月' }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>

            <a-col :span="8">
              <a-form-item label="还款频率：" name="repayRate">
                <a-select v-model:value="formData.repayRate" placeholder="请选择" style="width: 400rem">
                  <a-select-option value="M">月</a-select-option>
                  <a-select-option value="S">季度</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>

            <a-col :span="8" v-show="showState.leaseRate">
              <a-form-item label="租赁利率：" name="leaseRate">
                <a-input-number
                  v-model:value="formData.leaseRate"
                  :min="0.0"
                  :max="100"
                  :precision="2"
                  :step="0.1"
                  placeholder="请输入"
                  style="width: 400rem"
                />
              </a-form-item>
            </a-col>

            <a-col :span="8">
              <a-form-item label="租金支付方式：" name="payWay">
                <a-select v-model:value="formData.payWay" placeholder="请选择" style="width: 400rem">
                  <a-select-option value="YDBJ">约定本金</a-select-option>
                  <a-select-option value="DEBJ">等额本金</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>

            <a-col :span="8" v-show="formData.payWay == 'YDBJ'">
              <a-form-item label="小额还本金额：" name="smallAmount">
                <a-input-number
                  v-model:value="formData.smallAmount"
                  :min="0.0"
                  :precision="2"
                  :step="1"
                  @blur="blurNumber"
                  placeholder="请输入"
                  style="width: 400rem"
                />
              </a-form-item>
            </a-col>

            <a-col :span="8" v-show="formData.payWay == 'YDBJ'">
              <a-form-item label="大额还本时间：" name="bigAmtMonthArr">
                <a-select v-model:value="formData.bigAmtMonthArr" mode="multiple" :maxTagCount="3" placeholder="请选择" style="width: 400rem">
                  <a-select-option v-for="item in bigPayMonthList" :key="item.value" :value="item.value">{{ item.label }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>

            <a-col :span="8" v-show="showState.freePeriod">
              <a-form-item label="免息期：" name="freePeriod">
                <a-select v-model:value="formData.freePeriod" placeholder="请选择" style="width: 400rem">
                  <a-select-option v-for="item in freePeriodList" :key="item.value" :value="item.value">{{ item.label }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>

            <a-col :span="8" v-show="userStore.getRole == '0' && showState.rebateFirmAmt">
              <a-form-item label="贴息金额：" name="rebateFirmAmt">
                <a-input-number
                  v-model:value="formData.rebateFirmAmt"
                  :min="0.0"
                  :precision="2"
                  :step="1"
                  @blur="blurNumber"
                  placeholder="请输入"
                  style="width: 400rem"
                />
              </a-form-item>
            </a-col>

            <a-col :span="8" v-show="userStore.getRole == '0' && showState.firmRebateIntrestDate">
              <a-form-item label="贴息时间：" name="firmRebateIntrestDate">
                <a-select v-model:value="formData.firmRebateIntrestDate" placeholder="请选择" style="width: 400rem">
                  <a-select-option value="before45">起租前</a-select-option>
                  <a-select-option value="after45">起租后45天</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>

            <a-col :span="8" v-show="showState.lesseeRiskRate">
              <a-form-item label="风险金比例：" name="lesseeRiskRate">
                <a-select v-model:value="formData.lesseeRiskRate" placeholder="请选择" style="width: 400rem">
                  <a-select-option value="0">0%</a-select-option>
                  <a-select-option value="5">5%</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>

            <a-col :span="8" v-show="showState.otherExpense">
              <a-form-item label="是否赠送保险：" name="otherExpense">
                <a-select v-model:value="formData.otherExpense" placeholder="请选择" style="width: 400rem">
                  <a-select-option value="Y">是</a-select-option>
                  <a-select-option value="N">否</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>

            <a-col :span="8" v-show="userStore.getRole == '0' && showState.needXirr">
              <a-form-item label="内部收益率：" name="needXirr">
                <a-input-number
                  v-model:value="formData.needXirr"
                  :min="0.0"
                  :max="100"
                  :precision="2"
                  :step="0.1"
                  @blur="blurNumber"
                  placeholder="请输入"
                  style="width: 400rem"
                />
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <div class="next">
        <a-button class="" @click="onBack">返回</a-button>
        <a-button class="submit" @click="handleNext">下一步</a-button>
      </div>
    </div>
  </div>
</template>

<script setup>
  import { reactive, toRefs, onBeforeMount, onMounted, ref } from 'vue';
  import Back from '/@/components/go-back/index.vue';
  import { useRoute, useRouter } from 'vue-router';
  import { rzApplyApi } from '/@/api/system/rzApply';
  import { useRzApplyStore } from '/@/store/modules/system/rzApply';
  import { useUserStore } from '/@/store/modules/system/user';
  import { message } from 'ant-design-vue';
  import XEUtils from 'xe-utils';
  let rzApplyStore = useRzApplyStore();
  let userStore = useUserStore();
  const router = useRouter();
  const route = useRoute();
  const labelCol = { style: { width: '150rem' } };
  const wrapperCol = { span: 14 };
  const showRentTable = ref(false);
  const formData = ref({
    //购置总价
    purchaseAmt: '',
    //首付比例
    firstPayRate: '',
    //首付金额
    firstPayAmt: '',
    //融资金额
    financeAmt: '',
    //起租日
    startDate: '',
    //截止日
    endDate: '',
    //租赁期限
    limitMonth: '',
    //租赁期限
    leaseTerm: '0',
    //租赁利率
    leaseRate: undefined,
    //租金支付方式
    payWay: '',
    //还款频率
    repayRate: '',
    //约定小额金额
    smallAmount: '',
    //约定大额月份
    bigAmtMonthArr: [],
    bigAmtMonth: '',
    //设备型号
    deviceType: '',
    //厂商贴息
    rebateFirmAmt: '',
    //厂商贴息时间
    firmRebateIntrestDate: '',
    //承租人风险金比例
    lesseeRiskRate: '',
    //承租人风险金
    lesseeRiskAmt: '',
    //承租人风险金时间
    lesseeRiskDate: '',
    //留购价
    depositAmt: '1',
    //厂商返利
    rebateAmt: '0',
    //其他风险金
    otherRiskAmt: '0',
    //其他风险金时间
    otherRiskDate: '',
    //贴息期内利率
    discountRate: '',
    //贴息期内是否固定小额
    discountSmall: '',
    //贴息时间
    discountTime: '',
    //报价方案名称
    priceSchemeType: '常规报价',
    //报价方案类型
    priceSchemeId: '0',
    //预期收益率
    needXirr: '',
    //免息期限
    freePeriod: '',
    //保险费用
    otherExpense: '',
    //保险费用时间
    otherExpenseDate: 'before45',
    //锁定利率
    leaseRateLock: false,
  });
  const showState = ref({
    leaseRate: true,
    freePeriod: true,
    rebateFirmAmt: true,
    firmRebateIntrestDate: true,
    lesseeRiskRate: true,
    otherExpense: true,
    needXirr: false,
  });
  const bussNo = ref('')
  const deviceOptions = ref([]);
  const brandTypeMap = ref({});
  const freePeriodList = ref([]);
  const bigPayMonthList = ref([]);
  const priceSchemeSelected = ref({});
  const priceSchemeList = ref([]);
  onMounted(async () => {
    const query = route.query;
    formData.value.priceSchemeId = query.priceSchemeId;
    bussNo.value = query.bussNo
    await getPriceSchemeData();
    await getBrandListData();
    await handlePriceSchemeChange();
    await resetData();
  });


  async function getPriceSchemeData() {
    const res = await rzApplyApi.configList({});
    if (res.code == 0) {
      priceSchemeList.value = [{ id: '0', templateName: '常规报价' }].concat(...res.data);
    }
  }
  function getBrandListData() {
    rzApplyApi.brandList({}).then((res) => {
      if (res.code == 0) {
        brandTypeMap.value = res.data;
        const options = [];
        XEUtils.objectEach(res.data, (item, key) => {
          const children = [];
          XEUtils.objectEach(item, (discount, type) => {
            children.push({ label: type, value: type });
          });
          options.push({ label: key, value: key, children });
        });
        deviceOptions.value = options;
      }
    });
  }

  function getPriceSchemeSubInfo(priceScheme) {
    if (priceScheme.id == '0') {
      return '';
    }
    let info = '';
    if (priceScheme.schemeType) {
      info = info + priceScheme.schemeType;
    }
    if (priceScheme.schemeType != '反推利率' && (priceScheme.leaseRate || priceScheme.leaseRate == '0')) {
      info = info + '、利率' + priceScheme.leaseRate + '%';
    }
    if (priceScheme.extraParam) {
      try {
        const jsonObj = JSON.parse(priceScheme.extraParam);
        if (jsonObj.discountRate) {
          info = info + '、贴息期内利率' + jsonObj.discountRate + '%';
        }
        if (jsonObj.smallAmount == '1') {
          info = info + '、贴息期内固定小额本金';
        }
        if (jsonObj.discountTime) {
          info = info + '、贴息时间' + (jsonObj.discountTime == 'after45' ? '起租后' : '起租前');
        }
      } catch (e) {}
    }
    if (priceScheme.discountFlag == '1') {
      info = info + '、享受贴息';
    } else if (priceScheme.discountFlag == '0') {
      info = info + '、不享受贴息';
    }
    if (priceScheme.freeMonth || priceScheme.freeMonth == '0') {
      info = info + '、' + priceScheme.freeMonth + '个月免息期';
    }
    if (priceScheme.riskRate || priceScheme.riskRate == '0') {
      info = info + '、风险金' + priceScheme.riskRate + '%';
    }
    if (priceScheme.payInsurance == '1') {
      info = info + '、赠送保险';
    } else if (priceScheme.payInsurance == '0') {
      info = info + '、不赠送保险';
    }
    if (userStore.getRole == '0' && priceScheme.earningRate) {
      info = info + '、收益率' + priceScheme.earningRate + '%';
    }
    return info;
  }
  function handleMoneyChange(flag) {
    if (flag != 3 && formData.value.purchaseAmt) {
      if (formData.value.firstPayRate) {
        formData.value.firstPayAmt = XEUtils.round(formData.value.purchaseAmt * formData.value.firstPayRate, 2);
      }
      formData.value.financeAmt = formData.value.purchaseAmt - formData.value.firstPayAmt;
    }
    if (flag == 3 && formData.value.purchaseAmt) {
      formData.value.financeAmt = formData.value.purchaseAmt - formData.value.firstPayAmt;
    }
  }
  function repayRateChange() {
    handleFreePeriod();
    handleBigPayMonth();
  }
  function handleFreePeriod() {
    if (!showState.value.freePeriod) {
      return;
    }
    if (formData.value.repayRate == 'M') {
      freePeriodList.value = [
        { label: '0期', value: '0' },
        { label: '3期', value: '3' },
        {
          label: '6期',
          value: '6',
        },
        { label: '9期', value: '9' },
        { label: '12期', value: '12' },
      ];
    } else {
      freePeriodList.value = [
        { label: '0期', value: '0' },
        { label: '1期', value: '1' },
        {
          label: '2期',
          value: '2',
        },
        { label: '3期', value: '3' },
        { label: '4期', value: '4' },
      ];
    }
    formData.value.freePeriod = '0';
  }
  function handleBigPayMonth() {
    if (formData.value.payWay == 'DEBJ') {
      formData.value.bigAmtMonthArr = [];
      formData.value.smallAmount = '0.00';
      return;
    }
    if (formData.value.repayRate == 'M') {
      const list = [];
      for (let i = 1; i < 13; i++) {
        list.push({ label: i + '月', value: i + '月' });
      }
      bigPayMonthList.value = list;
    } else if (formData.value.startDate) {
      const list = [];
      const startMonth = XEUtils.toDateString(formData.value.startDate, 'M') % 3;
      for (let i = 0; i < 4; i++) {
        const month = startMonth == 0 ? startMonth + 3 * (i + 1) : startMonth + 3 * i;
        list.push({ label: month + '月', value: month + '月' });
      }
      bigPayMonthList.value = list;
    }
    formData.value.bigAmtMonthArr = formData.value.startDate ? [XEUtils.toDateString(formData.value.startDate, 'M') + '月'] : [];
  }
  function getMonthSpace(date1, date2) {
    if (!date1 || !date2) {
      return 0;
    }
    let year1 = XEUtils.toDateString(date1, 'yyyy') * 1;
    let year2 = XEUtils.toDateString(date2, 'yyyy') * 1;
    let month1 = XEUtils.toDateString(date1, 'M') * 1;
    let month2 = XEUtils.toDateString(date2, 'M') * 1;
    let day1 = XEUtils.toDateString(date1, 'd') * 1;
    let day2 = XEUtils.toDateString(date2, 'd') * 1;
    let yearInterval = year1 - year2;
    if (month1 < month2 || (month1 == month2 && day1 <= day2)) {
      yearInterval = yearInterval - 1;
    }
    let monthInterval = month1 + 12 - month2;
    if (day1 > day2) {
      monthInterval = monthInterval + 1;
    }
    if (monthInterval % 12 == 0) {
      monthInterval = 12;
    } else {
      monthInterval = monthInterval % 12;
    }
    return yearInterval * 12 + monthInterval;
  }
  function handleLeaseTerm() {
    if (formData.value.startDate && formData.value.limitMonth) {
      formData.value.endDate = XEUtils.toDateString(XEUtils.getWhatMonth(formData.value.startDate, formData.value.limitMonth, 10), 'yyyy-MM-dd');
      const diff = getMonthSpace(formData.value.endDate, formData.value.startDate);
      formData.value.leaseTerm = diff;
    } else {
      formData.value.leaseTerm = '0';
    }
  }
  function blurNumber(e) {
    if (!e.target.value) {
      e.target.value = '0.00';
    }
  }
  function handlePriceSchemeChange() {
    if (formData.value.priceSchemeId == '0') {
      priceSchemeSelected.value = {};
      formData.value.priceSchemeType = '常规报价';
      formData.value.deviceType = '';
      formData.value.leaseRate = '';
      showState.value.leaseRate = true;
      formData.value.freePeriod = '0';
      showState.value.freePeriod = true;
      formData.value.lesseeRiskRate = '0';
      showState.value.lesseeRiskRate = true;
      formData.value.otherExpense = 'N';
      showState.value.otherExpense = true;
      formData.value.rebateFirmAmt = '0';
      showState.value.rebateFirmAmt = true;
      formData.value.firmRebateIntrestDate = 'after45';
      showState.value.firmRebateIntrestDate = true;
      formData.value.needXirr = '';
      showState.value.needXirr = false;
    } else {
      priceSchemeSelected.value = XEUtils.find(priceSchemeList.value, (item) => item.id == formData.value.priceSchemeId);
      formData.value.priceSchemeType = priceSchemeSelected.value.schemeType;
      formData.value.deviceType = '';
      if (priceSchemeSelected.value.schemeType == '反推利率') {
        showState.value.leaseRate = false;
        formData.value.leaseRate = '';
      } else if (priceSchemeSelected.value.leaseRate || priceSchemeSelected.value.leaseRate == '0') {
        showState.value.leaseRate = false;
        formData.value.leaseRate = priceSchemeSelected.value.leaseRate;
      } else {
        showState.value.leaseRate = true;
        formData.value.leaseRate = '';
      }
      if (priceSchemeSelected.value.freeMonth || priceSchemeSelected.value.freeMonth == '0') {
        showState.value.freePeriod = false;
        formData.value.freePeriod = priceSchemeSelected.value.freeMonth;
      } else {
        showState.value.freePeriod = true;
        formData.value.freePeriod = '';
      }
      if (priceSchemeSelected.value.discountFlag || priceSchemeSelected.value.discountFlag == '0') {
        formData.value.rebateFirmAmt = '0';
        showState.value.rebateFirmAmt = false;
        formData.value.firmRebateIntrestDate = 'after45';
        showState.value.firmRebateIntrestDate = false;
      } else {
        formData.value.rebateFirmAmt = '0';
        showState.value.rebateFirmAmt = userStore.getRole == '0';
        formData.value.firmRebateIntrestDate = 'after45';
        showState.value.firmRebateIntrestDate = userStore.getRole == '0';
      }
      if (priceSchemeSelected.value.riskRate || priceSchemeSelected.value.riskRate == '0') {
        showState.value.lesseeRiskRate = false;
        formData.value.lesseeRiskRate = priceSchemeSelected.value.riskRate;
      } else {
        showState.value.lesseeRiskRate = true;
        formData.value.lesseeRiskRate = '0';
      }
      if (priceSchemeSelected.value.payInsurance || priceSchemeSelected.value.payInsurance == '0') {
        showState.value.otherExpense = false;
        formData.value.otherExpense = priceSchemeSelected.value.payInsurance == '1' ? 'Y' : 'N';
      } else {
        showState.value.otherExpense = true;
        formData.value.otherExpense = 'N';
      }
      if (priceSchemeSelected.value.schemeType == '反推利率' || priceSchemeSelected.value.schemeType == '反推贴息') {
        showState.value.needXirr = userStore.getRole == '0' ? true : false;
        formData.value.needXirr = priceSchemeSelected.value.earningRate || '';
      } else {
        showState.value.needXirr = false;
        formData.value.needXirr = '';
      }
    }
  }
  function handleBrandDiscountChange(info) {
    if (info && info.length > 1) {
      const brand = info[0];
      const type = info[1];
      const typeInfo = brandTypeMap.value[brand] || {};
      const discountInfo = typeInfo[type] || {};
      const { discountAmt, discountDate } = discountInfo;
      if (discountAmt || discountAmt == '0') {
        formData.value.rebateFirmAmt = discountAmt;
        formData.value.firmRebateIntrestDate = discountDate == '起租前' ? 'before45' : 'after45';
      }
    }
  }
  function resetData() {
    formData.value.purchaseAmt = '0.00';
    formData.value.firstPayRate = '';
    formData.value.firstPayAmt = '0.00';
    formData.value.financeAmt = '0.00';
    formData.value.startDate = XEUtils.toDateString(new Date(), 'yyyy-MM-dd');
    formData.value.limitMonth = 36;
    formData.value.repayRate = 'M';
    formData.value.payWay = 'YDBJ';
    formData.value.smallAmount = '0.00';
    if (showState.value.leaseRate) {
      formData.value.leaseRate = undefined;
    }
    if (showState.value.rebateFirmAmt) {
      formData.value.rebateFirmAmt = '0.00';
    }
    if (showState.value.firmRebateIntrestDate) {
      formData.value.firmRebateIntrestDate = 'after45';
    }
    if (showState.value.freePeriod) {
      formData.value.freePeriod = '0';
    }
    if (showState.value.lesseeRiskRate) {
      formData.value.lesseeRiskRate = '0';
    }
    if (showState.value.otherExpense) {
      formData.value.otherExpense = 'N';
    }
    handleFreePeriod();
    handleBigPayMonth();
    handleLeaseTerm();
  }
  function checkData() {
    if (priceSchemeSelected.value.discountFlag == '1' && !formData.value.deviceType) {
      return '请选择品牌型号';
    }
    if (!formData.value.purchaseAmt) {
      return '购置总价需要大于0';
    }
    if (!formData.value.firstPayAmt) {
      return '首付金额需要大于0';
    }
    if (!formData.value.startDate) {
      return '请选择计划起租日';
    }
    if (!formData.value.limitMonth || !formData.value.leaseTerm) {
      return '请选择租赁期限';
    }
    if (showState.value.leaseRate && !formData.value.leaseRate && formData.value.leaseRate != '0') {
      return '请输入租赁利率';
    }
    if (XEUtils.toNumber(formData.value.firstPayAmt) > XEUtils.toNumber(formData.value.purchaseAmt)) {
      return '首付金额不能大于购置总价';
    }
    if (XEUtils.toNumber(formData.value.financeAmt) <= 0) {
      return '融资金额需要大于0';
    }
    if (XEUtils.toNumber(formData.value.financeAmt) > XEUtils.toNumber(formData.value.purchaseAmt)) {
      return '融资金额不能大于购置总价';
    }
    if (XEUtils.divide(XEUtils.toNumber(formData.value.firstPayAmt), XEUtils.toNumber(formData.value.purchaseAmt)) < 0.1) {
      return '首付金额不能低于购置总价的10%';
    }
    if (
      XEUtils.toNumber(formData.value.smallAmount) > 0 &&
      XEUtils.toNumber(formData.value.smallAmount) * formData.value.limitMonth > XEUtils.toNumber(formData.value.financeAmt)
    ) {
      return '小额还本累加金额不能大于融资金额';
    }
    if (userStore.getRole == '0' && showState.value.needXirr && !formData.value.needXirr && formData.value.needXirr != '0') {
      return '请输入内部收益率';
    }
  }
  function onBack(){
    router.back()
  }
  function handleNext() {
    const msg = checkData();
    console.log();
    if (msg) {
      message.warning(msg);
      return;
    }
    formData.value.lesseeRiskAmt = (XEUtils.toNumber(formData.value.financeAmt) * XEUtils.toNumber(formData.value.lesseeRiskRate)) / 100;
    formData.value.bigAmtMonth =
      formData.value.bigAmtMonthArr && formData.value.bigAmtMonthArr.length > 0 ? formData.value.bigAmtMonthArr.join(',') : '';
    formData.value.lesseeRiskDate = formData.value.startDate;
    formData.value.otherRiskDate = formData.value.startDate;
    if (priceSchemeSelected.value.extraParam) {
      try {
        const jsonObj = JSON.parse(priceSchemeSelected.value.extraParam) || {};
        formData.value.discountRate = jsonObj.discountRate;
        formData.value.discountSmall = jsonObj.smallAmount;
        formData.value.discountTime = jsonObj.discountTime;
      } catch (e) {
        formData.value.discountRate = '';
        formData.value.discountSmall = '';
        formData.value.discountTime = '';
      }
    } else {
      formData.value.discountRate = '';
      formData.value.discountSmall = '';
      formData.value.discountTime = '';
    }
    formData.value.leaseRateLock = !showState.value.leaseRate;
    showRentTable.value = true;
    rzApplyStore.setCalcTrialParam(formData.value)
    router.push({ path: '/rzApply/planDetail' ,query:{
      bussNo:bussNo.value
    }});
  }
</script>
<style scoped lang="less">
  @import url(../rzApply/index.less);
  .state {
    font-family: Microsoft YaHei;
    font-size: 22px;
    color: #1169e5;
    display: flex;
    align-items: center;
    margin-bottom: 32rem;
    img {
      width: 19px;
      height: 23px;
      margin-right: 12px;
    }
  }
  /deep/.ant-form {
    .ant-form-item {
      margin-bottom: 24rem;
    }
  }
</style>
